###
##Content Analysis of Sports Articles from Experimental Treatments and Random Sample of ESPN's Homepage
###

library(plyr)
library(xtable)

load('labeled.sports.articles.RData')
load('researcher.labeled.sports.articles.RData')

political.out <- ddply(labeled.sports.articles,.(HITId,category),summarise,political.restrictive=mean(political.sure,na.rm=TRUE),political.broad=mean(political.maybe,na.rm=TRUE),slantdem=mean(demslant,na.rm=TRUE),slantrep=mean(repslant,na.rm=TRUE))

political.out$political.label <- ifelse(political.out$political.broad > .2, 1, 0)

researcher.labeled.sports.articles <- researcher.labeled.sports.articles[,c('HITId','political.label.researcher')]

political.out <- merge(political.out,researcher.labeled.sports.articles,by=c('HITId'),all.x=TRUE)
political.out$agreement <- ifelse(political.out$political.label==political.out$political.label.researcher, 1, 0)

#Researcher Agreement with Crowd-Sourced Labels
mean(political.out$agreement,na.rm=TRUE)

category.comparison <- ddply(political.out,.(category),summarise,political.summary=round(mean(political.label,na.rm=TRUE),digits=2),political.broad=round(mean(political.broad,na.rm=TRUE),digits=2),demslant=round(mean(slantdem,na.rm=TRUE),digits=2),repslant=round(mean(slantrep,na.rm=TRUE),digits=2))
names(category.comparison) <- c('Category','Political (Binary)','Political (Share)','Dem Slant','Rep Slant')

#Table B2 Content Analysis
xtable(category.comparison,caption="Content Analysis of Experimental Treatments and Typical ESPN Sports Coverage")
